package com.baizan.daka.ui.activity
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.graphics.Color
import com.baizan.daka.base.BasePageListActivity
import com.baizan.daka.mvp.model.bean.UserCaplitalDes
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.ui.adapter.CapitalDesAdapter
import com.baizan.daka.ui.contract.CaplitalDesContract
import com.baizan.daka.ui.dialog.ButtomDialog
import com.baizan.daka.ui.presenter.CapitalDesPresenter
import com.baizan.daka.util.HyperTextUtil
import com.dianzan.daka.R
import kotlinx.android.synthetic.main.act_capital_des.*

class CapitalDesListActivity : BasePageListActivity<CapitalDesPresenter, CapitalDesAdapter>(),
    CaplitalDesContract.View {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, CapitalDesListActivity::class.java)
            context.startActivity(intent)
        }
    }


    override fun onRefresh() {

    }

    override fun onLoadMore() {

    }

    override fun initAdapter(): CapitalDesAdapter = CapitalDesAdapter()

    override fun initPresenter(): CapitalDesPresenter = CapitalDesPresenter(this)

    override fun initView() {
        capital_title_tv.text =
            HyperTextUtil.build("资金来源：").appendColor("提现", Color.parseColor("#5A5A5A")).Builder()
        capital_title_tv.setOnClickListener {
            val pictureSelectionStr: Array<String> = arrayOf("全部","提现", "充值会员", "购买套餐", "任务奖励",
                "任务分佣", "套餐奖励","会员奖励")
            val builder: ButtomDialog.Builder = ButtomDialog.Builder(this)
            builder.setContentData(pictureSelectionStr)
            builder.setListener(object : ButtomDialog.OnItemSelectListener {

                override fun OnItemSelected(dialog: Dialog, position: Int, title: String?) {
                    when (position) {
                        4 -> dialog.dismiss()
                        else -> {
                            setTitleAndLoadData(title!!)
                            dialog.dismiss()
                        }
                    }
                }
            })
            builder.Build().show()
        }
    }

    private fun setTitleAndLoadData(text: String) {
        mCurrentPageNo = 0
        capital_title_tv.text = HyperTextUtil.build("交易类型：")
            .appendColor(text!!, Color.parseColor("#5A5A5A")).Builder()

        when (text) {
            "提现" -> {
                presenter?.loadData(mCurrentPageNo, "1")
            }
            "充值会员" -> {
                presenter?.loadData(mCurrentPageNo, "2")
            }
            "购买套餐" -> {
                presenter?.loadData(mCurrentPageNo, "3")
            }
            "任务奖励" -> {
                presenter?.loadData(mCurrentPageNo, "4")
            }
            "任务分佣" -> {
                presenter?.loadData(mCurrentPageNo, "5")
            }
            "套餐奖励" -> {
                presenter?.loadData(mCurrentPageNo, "6")
            }
            "会员奖励" -> {
                presenter?.loadData(mCurrentPageNo, "7")
            }
            "全部"->{
                presenter?.loadData(mCurrentPageNo, null)
            }
        }
    }

    override fun start() {
        setTitleAndLoadData("全部")
    }


    override fun layoutId(): Int = R.layout.act_capital_des

    override fun loadSuccess(date: BasePageResponse<UserCaplitalDes>) {
        getDatasSuccess(date)
    }
}